import React from 'react'
import Component, { mapStateToProps, mapDispatchToProps } from '@components/Component'
import { connect } from 'react-redux'
import { Modal, Form, message } from 'antd'
import PropTypes from 'prop-types'
import { requestOneFile } from '@js/request'
const { Item } = Form
class InfoModal extends Component {
  state = {
    fileList: []
  }

  formRef = React.createRef()

  onFinish (data) {
    const hide = message.loading('上传中', 120)
    requestOneFile(data.file[0])
      .then(({ data: res }) => {
        hide()
        if (res.status !== 1) {
          return message.warning(res.message)
        }
        this.props.onChange(res.data.id)
      })
      .catch(() => hide())
  }

  render () {
    const d = this.props.data
    return (
      <Modal
        title='会议信息'
        open={this.props.visible}
        onCancel={() => this.props.hide()}
        footer={null}
        destroyOnClose
      >
        <Form ref={this.formRef} labelCol={{ flex: '128px' }} onFinish={d => this.onFinish(d)}>
          <Item label='会议ID'>
            <span>{d.conferenceid || '无'}</span>
          </Item>
          <Item label='主持人 会议密码'>
            <span>{d.chairpwd || '无'}</span>
          </Item>
          <Item label='非主持人 会议密码'>
            <span>{d.generalpwd || '无'}</span>
          </Item>
        </Form>
      </Modal>
    )
  }
}

InfoModal.proptypes = {
  visible: PropTypes.bool,
  data: PropTypes.object,
  hide: PropTypes.func
}

InfoModal.defaultProps = {
  visible: false,
  data: {},
  hide: () => {}
}

const mapState = mapStateToProps(function (state) {
  return {
    userInfo: state.basic.userInfo
  }
})

const mapDispatch = mapDispatchToProps(function (dispatch) {
  return {
  }
})

export default connect(mapState, mapDispatch)(InfoModal)
